<template>
	<view>
		<view v-if="list.length == 0" class="my-nodata">
			<image src="../../static/images/no-data.png"></image>
			<view class="no-data-text">
				<text>无数据</text>
			</view>
		</view>
		<view class="cu-card dynamic "  style="margin-bottom: 50px;">
			<view class="cu-item shadow" v-for="(item,index) in list">
				<view class="cu-list menu-avatar line">
					<view class="cu-item my-card">
						<view class='cu-tag radius bg-blue' style="margin-top: -100px;margin-right: 10px;" v-if="item.isDefault == 1">默认</view>
						<view class="collection" >
							<image src="../static/yinhangka.png" class="collection-image" mode="aspectFit" v-if="item.payType ==1"></image>
							<image src="../static/zhifubao.png" mode="aspectFit" v-if="item.payType ==2"></image>
						</view>
						<view class="content flex-sub" v-if="item.payType == 1">
							<view class="text-gray text-sm flex justify-between">								真实姓名：{{item.fullName}}							</view>
							<view class="text-gray text-sm flex justify-between">
								银行名称：{{item.backName}}
							</view>							<view class="text-gray text-sm flex justify-between">								银行卡号：{{item.account}}							</view>							<view class="text-gray text-sm flex justify-between">								身份证号：{{item.idCard}}							</view>							<view class="text-gray text-sm flex justify-between">								预留电话：{{item.resMobile}}							</view>
						</view>
						<view class="content flex-sub" v-if="item.payType == 2">
							<view class="text-gray text-sm flex justify-between">
								真实姓名：{{item.fullName}}
							</view>
							<view class="text-gray text-sm flex justify-between">
								支付宝账号：{{item.account}}
							</view>
							<view class="text-gray text-sm flex justify-between">
								身份证号：{{item.idCard}}
							</view>
							<view class="text-gray text-sm flex justify-between">
								预留电话：{{item.resMobile}}
							</view>
						</view>
					</view>
				</view>
				<view class="text-gray text-sm text-right my-padding">
					<button  class="cu-btn round lines-grey my-button" :data-id="item.id" @click="clickDelete">删除</button>
					<button  class="cu-btn round lines-blue " v-if="item.isDefault == 0" 
					:data-id="item.id" @click="clickDefault">设为默认</button>
				</view>
			</view>
			
		</view>
		<view class="padding flex flex-direction my-add">
			<button class="cu-btn bg-blue lg" @click="addCollection">添加收款账户</button>
		</view>
		
	</view>
</template>

<script>
	
	const http = require('../../utils/http.js');

	export default {
		components: {
		},
		data() {
			return {
				list:null,
			}
		},
		onLoad: function(options) {
		  this.loadData();
		},
		onShow: function () {
		},
		methods: {
			addCollection:function(){
				uni.navigateTo({
					url:'/pages_user/addCollection/addCollection'
				})
			},
			loadData:function(){
				let that = this;
				uni.showLoading({
				    title: '加载中'
				});
				
				
				var params = {
				    url: '/u/collection/selectList',
				    method: 'POST',
					baseUrl:true,
				    data: {},
				    callBack: function (res) {
				        uni.hideLoading();
				        if (res.code == 200) {
				            that.list = res.data;
				        } else {
				            uni.showToast({
				                title: res.msg,
				                duration: 2000,
				                icon: 'none'
				            });
				        }
				    }
				};
				http.request(params);
			},
			clickDelete:function(e){
				let id =  e.currentTarget.dataset.id;
				let that = this;
				
				uni.showModal({
					title:'提示',
					content:'确定删除吗?',
					success(res) {
						if(res.confirm){
							uni.showLoading({
							    title: '加载中'
							});
							var params = {
							    url: '/u/collection/clickDelete',
							    method: 'get',
								baseUrl:true,
							    data: {id:id},
							    callBack: function (res) {
							        uni.hideLoading();
							        if (res.code == 200) {
							            that.loadData();
							        } else {
							            uni.showToast({
							                title: res.msg,
							                duration: 2000,
							                icon: 'none'
							            });
							        }
							    }
							};
							http.request(params);
						}
					}
				})
				
				
			},
			clickDefault:function(e){
				let id =  e.currentTarget.dataset.id;
				let that = this;
				
				uni.showModal({
					title:'提示',
					content:'确定设为默认吗?',
					success(res) {
						if(res.confirm){
							uni.showLoading({
							    title: '加载中'
							});
							var params = {
							    url: '/u/collection/clickDefault',
							    method: 'get',
								baseUrl:true,
							    data: {id:id},
							    callBack: function (res) {
							        uni.hideLoading();
							        if (res.code == 200) {
							            that.loadData();
							        } else {
							            uni.showToast({
							                title: res.msg,
							                duration: 2000,
							                icon: 'none'
							            });
							        }
							    }
							};
							http.request(params);
						}
					}
				})
				
			}
		}
	}
</script>

<style>
@import "./collection.css";
</style>
